package com.property.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.property.biz.ProvCityDistBiz;
import com.property.entity.ProvCityDist;

@Controller
@RequestMapping("/address")
public class AddressController {

	@Autowired
	private ProvCityDistBiz provCityDistBiz;

	@RequestMapping(value = "getProvince",method  = RequestMethod.POST)
	@ResponseBody
	public List<ProvCityDist> getProvince() {
		List<ProvCityDist> areas = provCityDistBiz.getProv("0");
		return areas;
	}

	@RequestMapping(value = "getCity",method  = RequestMethod.POST)
	@ResponseBody
	public List<ProvCityDist> getCity(Integer id) {
		List<ProvCityDist> areas = provCityDistBiz.getCity(id);
		return areas;
	}

	@RequestMapping(value = "getArea",method  = RequestMethod.POST)
	@ResponseBody
	public List<ProvCityDist> getArea(Integer id) {
		List<ProvCityDist> areas = provCityDistBiz.getDist(id);
		return areas;
	}
	
	@RequestMapping(value = "getAddress",method  = RequestMethod.POST)
	public void getAddress(HttpServletResponse response,Integer id) throws IOException{
		ProvCityDist dist = provCityDistBiz.distAll(id);
		ProvCityDist city = provCityDistBiz.distAll(dist.getCity_id());
		ProvCityDist prov = provCityDistBiz.distAll(city.getProvince_id());
		String address=prov.getProvince()+" "+city.getCity()+" "+dist.getDistrict();
		System.out.println(address);
		response.setContentType("text/html; charset=UTF-8"); // 转码
		PrintWriter out=response.getWriter();
		out.print(address);
	}
}
